package com.woniu.inlet.web;

import com.woniu.feignClient.ProPlanClient;
import com.woniu.outlet.po.ProPlanPo;
import com.woniu.utils.ResponseResult;
import com.woniu.utils.ResultCode;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
//@DefaultProperties(defaultFallback = "fallBackMethod") // 指定一个类的全局降级方法
public class ProPlanController {

    @Autowired
    @Qualifier("proPlan1")
    private ProPlanClient proPlanClient;

    @GetMapping("getPlanByOrderId")
//    @HystrixCommand // 标记该方法需要降级
    @ApiOperation("根据订单id查询生产计划信息")
    public ResponseResult<ProPlanPo> findAllProPlan(@RequestParam("orderId") Long orderId){
//        try {
//            Thread.sleep(8000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        ResponseResult<ProPlanPo> allProPlan = this.proPlanClient.findAllProPlan(orderId);
        return new ResponseResult<>(allProPlan.getData(), "OK", ResultCode.SUCCESS.getCode());
    }


    /**
     * 降级方法
     * 返回值要和被降级的方法的返回值一致
     * 降级方法不需要参数
     * @return
     */
    public String fallBackMethod(){

        return "请求繁忙，请稍后再试！";
    }
}